package user

import (
	"api/pb/user"
	"context"

	"api/internal/svc"
	"api/internal/types"

	"github.com/zeromicro/go-zero/core/logx"
)

type GetUserLogic struct {
	logx.Logger
	ctx    context.Context
	svcCtx *svc.ServiceContext
}

func NewGetUserLogic(ctx context.Context, svcCtx *svc.ServiceContext) *GetUserLogic {
	return &GetUserLogic{
		Logger: logx.WithContext(ctx),
		ctx:    ctx,
		svcCtx: svcCtx,
	}
}

func (l *GetUserLogic) GetUser(req *types.UserIDRequest) (resp *types.User, err error) {
	u, err := l.svcCtx.UserRpc.GetUserByID(l.ctx, &user.IDRequest{Id: req.UserId})
	if err != nil {
		return nil, err
	}
	return &types.User{Id: u.Id, Name: u.Name, Password: u.Password}, nil
}
